package com.hangwei.paperless.zxing;

import android.content.Intent;
import android.os.Bundle;

import com.hangwei.paperless.MainRepairActivity;
import com.hangwei.paperless.SubRepairActivity;
import com.hangwei.paperless.model.bean.QRBean;
import com.hangwei.paperless.presenter.StaticPresenter;
import com.twelve.all.base.BaseActivity;
import com.twelve.all.net.CallBack;
import com.twelve.all.utils.LoadingDialog;
import com.twelve.all.utils.LogUtil;
import com.twelve.all.utils.SPKey;
import com.twelve.all.utils.SPUtil;
import com.twelve.all.utils.ToastUtil;

public class ResultActivity extends BaseActivity {


    private String mOldUserId;
    private String mOrderId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_result);

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            String result = bundle.getString("result");
            LogUtil.i("result:" + result);
            final String[] split = result.split(":");
            if (split.length == 2 && split[0].equals("ExSheet")) {
                LoadingDialog loadingDialog = new LoadingDialog(this);
                loadingDialog.show();
                String userId = SPUtil.getString(SPKey.Account.USER_ID);
                StaticPresenter.getRoutingSheetByQRCode(userId,result, new CallBack<QRBean>() {
                    @Override
                    public void onCompleted(QRBean qrBean) {
                        loadingDialog.dismiss();
                        Intent intent = new Intent();
                        if ("GeneralRoutingSheet".equals(qrBean.sheetTypeNumber)) {
                            intent.setClass(ResultActivity.this, MainRepairActivity.class);
                        } else if ("RoutingSheet".equals(qrBean.sheetTypeNumber)) {
                            intent.setClass(ResultActivity.this, SubRepairActivity.class);
                            intent.putExtra("isLotDataSheet", qrBean.isLotDataSheet);
                        } else if ("ModifyRoutingSheet".equals(qrBean.sheetTypeNumber)) {
                            intent.setClass(ResultActivity.this, MainRepairActivity.class);
                        }
                        intent.putExtra("id", split[1]);
                        intent.putExtra("woNo", qrBean.woNo);
                        intent.putExtra("pwoNo", qrBean.pwoNo);
                        intent.putExtra("pn", qrBean.pn);
                        intent.putExtra("sn", qrBean.sn);
                        intent.putExtra("description", qrBean.description);
                        intent.putExtra("step", qrBean.curExStep);
                        startActivity(intent);
                        finish();
                    }

                    @Override
                    public void onError() {
                        loadingDialog.dismiss();
                        finish();
                    }
                });
            } else {
                ToastUtil.showCenterToast("无效二维码！");
            }
//            Intent intent = new Intent(this, SaveOrderActivity.class);
//            intent.putExtra("id",mOrderId);
//            intent.putExtra("type","trans");
//            startActivityForResult(intent, 10);
        }
    }
}


